<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
   <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="异常事件编号">
              <p-input placeholder="请输入" allowClear v-model="queryParam.exceptionEventNum"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
            </span>
          </p-col>
        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
          <p-button
            v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
            :key=" 'cgbtn'+index "
            @click="cgButtonJsHandler(item.buttonCode)"
            type="primary"
            :icon="item.buttonIcon"
          >{{ item.buttonName }}</p-button>
          <p-button
            v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
            :key=" 'cgbtn'+index "
            @click="cgButtonActionHandler(item.buttonCode)"
            type="primary"
            :icon="item.buttonIcon"
          >{{ item.buttonName }}</p-button>
      </template>

        <!-- 高级查询区域 -->
        <j-super-query :fieldList="fieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>

      <p-dropdown  v-for="(item,index) in groupTag" :key="index">
        <p-button >
          {{item.name}}
          <p-icon type="down" />
        </p-button>
          <p-menu slot="overlay"  >
            <template  v-for="(items,indexs) in item.data">
              <p-menu-item v-if=" items.optType=='js' " :key="indexs" @click="cgButtonJsHandler(items.buttonCode)">
                <p-icon :type="items.buttonIcon" />{{items.buttonName}}
              </p-menu-item>
              <p-menu-item v-else-if=" items.optType=='action' " :key="indexs" @click="cgButtonActionHandler(items.buttonCode)">
                <p-icon :type="items.buttonIcon" />{{items.buttonName}}
              </p-menu-item>
            </template>
          </p-menu>
      </p-dropdown>

    </div>
    <!-- table区域-begin -->
    <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>

            <span style="float:right;">
              <!-- <a @click="handleExportXls('异常呼叫')"><p-icon type="download" />导出</a>
                 <p-divider type="vertical" />
              <p-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
                 <a><p-icon type="import" />导入</a>
              </p-upload>
              <p-divider type="vertical" /> -->
              <a @click="loadData()"><p-icon type="sync" />刷新</a>
              <p-divider type="vertical" />
                <p-popover title="自定义列" trigger="click" placement="leftBottom"  :overlay-style="getWidth">
                <template slot="content">
                  <p-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                    <p-row>
                      <template v-for="(item,index) in defColumns">
                        <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                            <p-col :span="12"><p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox></p-col>
                        </template>
                      </template>
                    </p-row>
                  </p-checkbox-group>
                </template>
                <a><p-icon type="setting" />自定义列</a>
              </p-popover>
            </span>
        </div>

      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="tableScroll"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="exceptionEventNum" slot-scope="text, record">
          <a @click="exceptionEventNumClick(record)">{{record.exceptionEventNum}}</a>
        </template>
        <template slot="exceptionBillStatus" slot-scope="text, record">
          <span v-if="record.exceptionBillStatus == 11">{{exceptionBillStatusMap[record.exceptionBillStatus]}}</span>
          <a v-else @click="exceptionBillStatusClick(record)">{{exceptionBillStatusMap[record.exceptionBillStatus]}}</a>
        </template>
          <!-- <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template> -->
            <!-- <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
              <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
            </template> -->
            <!-- <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
              <p-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="uploadFile(text)">
                下载
              </p-button>
            </template> -->

            <!-- <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>

              <p-divider type="vertical" />
              <p-dropdown>
                <a class="ant-dropdown-link">更多 <p-icon type="down" /></a>
                <p-menu slot="overlay">
                  <p-menu-item>
                    <p-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </p-popconfirm>
                  </p-menu-item>
                    <template v-if="cgButtonLinkList && cgButtonLinkList.length>0" v-for="(btnItem,btnIndex) in cgButtonLinkList">
                      <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                        <a href="javascript:void(0);" @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)">
                          <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                          {{ btnItem.buttonName }}
                        </a>
                      </p-menu-item>
                    </template>
                </p-menu>
              </p-dropdown>
            </span> -->
      </p-table>
    </div>
    <!-- table区域-end -->
    <mesMfAbnormalCall-modal ref="modalForm" :EnhanceJS="EnhanceJS"  @ok="modalFormOk"></mesMfAbnormalCall-modal>
     <!-- 弹出窗 -->
     <Fx-compontens-modal @ok="modalFormOk"  ref="modalCompon" :getList="queryInfo" :title="title" :dictOptions="dictOptions"></Fx-compontens-modal>
     <!--  -->
     <keep-alive>
        <component v-model="visibleModal" :is="componentId" :data="curRow"></component>
     </keep-alive>
  </p-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import {api} from '@/api/manage'
import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
import { filterObj } from '@/utils/util';

import Vue from 'vue'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
import { postAction,getAction,deleteAction } from '@/api/manage'
import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"
import yccl from "./modules/unProduct/yccl";
import dycccz from "./modules/unProduct/dycccz";
import dgyxzcl from "./modules/unProduct/dgyxzcl";
import ycclfaqr from "./modules/unProduct/ycclfaqr";
import scclycd from "./modules/unProduct/scclycd";
import ycfpPQEpd from "./modules/product/ycfpPQEpd";
import ycsh from "./modules/product/ycsh";
import ycczlscs from "./modules/product/ycczlscs";
import yyjcqcs from "./modules/product/yyjcqcs";
import productUnusual from "@/api/productUnusual";

  //高级查询modal需要参数
  const superQueryFieldList=[
    {
        value:'exceptionEventNum',
        text: '异常事件编号',
        type: 'String'
    },
    {
        value:'exceptionType',
        text: '异常类型',
        type: 'String'
    },
    {
      title: '工序工单',
      value:'processNum',
      type: 'String'
    },
    {
      title: '异常二级工序',
      value:'exceptionSecondProcess',
      type: 'String'
    },
    {
      title: '线体',
      value:'lineName',
      type: 'String'
    },
    {
      title: '异常工站',
      value:'exceptionWorkstation',
      type: 'String'
    },
    {
      title: '物料编码',
      value:'exceptionMaterielCode',
      type: 'String'
    },
    {
      title: '物料名称',
      value:'exceptionMaterielName',
      type: 'String'
    },
    {
      title: '异常描述',
      value:'exceptionDesc',
      type: 'String'
    },
    {
      title: '异常发起人',
      value:'exceptionCreateUser',
      type: 'String'
    },
    {
      title: '异常发起时间',
      value:'exceptionCreateTime',
      type: 'String'
    },
    {
      title: '异常关闭时间',
      value:'exceptionCloseTime',
      type: 'String'
    },
    {
      title: '当前处理部门',
      value:'currentHandleDepart',
      type: 'String'
    },
    {
      title: '当前处理人',
      value:'currentHandleUser',
      type: 'String'
    },
    {
      title: '状态',
      value:'exceptionBillStatus',
      type: 'String'
    },
  ]

  export default {
    name: "MesMfAbnormalCallList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      FxCompontensModal,
      yccl,
      dycccz,
      dgyxzcl,
      ycclfaqr,
      scclycd,
      ycfpPQEpd,
      ycsh,
      ycczlscs,
      yyjcqcs,
    },
    data () {
      return {
        visibleModal: false,
        componentId: "",
        curRow: {},
        exceptionBillStatusMap: {
          /* 1: '异常分配（主管）',
          2: '待异常处置',
          3: '待工艺协助处理',
          4: '异常处置方案验证',
          5: '关闭',
          6: '异常分配(PQE判定)',
          7: '异常审核(主管审核)', */
          // 11: '关闭'
        },
        exceptionTypeMap: {},
        // 4: '异常处置方案验证（线长确认）',
        fieldList:superQueryFieldList,
        superQueryFlag:false,
        superQueryParams: '',
        description: '异常呼叫管理页面',
        cgButtonLinkList:[],
        title:'',//存表名
        EnhanceJS:'',
        cgButtonList:[],
        groupTag:[],
        queryInfo: [],
        code: '',
        // 表头
        columns: [
        ],
        //列设置
        settingColumns:[],
        dataSource: [
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '非产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 0,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '非产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 1,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '非产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 2,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '非产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 11,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '非产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 3,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 4,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '产品异常',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 5,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '产品异常处置验证',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 6,
          },
          {
            id: '1',
            exceptionEventNum: '异常事件编号',
            exceptionType: '产品异常处置验证',
            processNum: '工序工单',
            exceptionSecondProcess: '异常二级工序',
            lineName: '线体',
            exceptionWorkstation: '异常工站',
            exceptionMaterielCode: '物料编码',
            exceptionMaterielName: '物料名称',
            exceptionDesc: '异常描述',
            exceptionCreateUser: '异常发起人',
            exceptionCreateTime: '异常发起时间',
            exceptionCloseTime: '异常关闭时间',
            currentHandleDepart: '当前处理部门',
            currentHandleUser: '当前处理人',
            exceptionBillStatus: 7,
          },
        ],
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: '',
            key:'rowIndex',
            width: 60,
            align: 'center',
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '异常事件编号',
            align: 'center',
            dataIndex: 'exceptionEventNum',
            scopedSlots: {customRender: 'exceptionEventNum'},
            // sorter: (a, b) => a.exceptionEventNum - b.exceptionEventNum
          },
          {
            title: '异常类型',
            align: 'center',
            dataIndex: 'exceptionType',
            // sorter: (a, b) => a.exceptionType - b.exceptionType
          },
          {
            title: '工序工单',
            align: 'center',
            dataIndex: 'processNum',
            // sorter: (a, b) => a.processNum - b.processNum
          },
          {
            title: '异常二级工序',
            align: 'center',
            dataIndex: 'exceptionSecondProcess',
            // sorter: (a, b) => a.exceptionSecondProcess - b.exceptionSecondProcess
          },
          {
            title: '线体',
            align: 'center',
            dataIndex: 'lineName',
            // sorter: (a, b) => a.lineName - b.lineName
          },
          {
            title: '异常工站',
            align: 'center',
            dataIndex: 'exceptionWorkstation',
          },
          {
            title: '物料编码',
            align: 'center',
            dataIndex: 'exceptionMaterielCode',
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'exceptionMaterielName',
          },
          {
            title: '异常描述 ',
            align: 'center',
            dataIndex: 'exceptionDesc',
          },
          {
            title: '异常发起人',
            align: 'center',
            dataIndex: 'exceptionCreateUser',
          },
          {
            title: '异常发起时间',
            align: 'center',
            dataIndex: 'exceptionCreateTime',
          },
          {
            title: '异常关闭时间',
            align: 'center',
            dataIndex: 'exceptionCloseTime',
          },
          {
            title: '当前处理部门 ',
            align: 'center',
            dataIndex: 'currentHandleDepart',
          },
          {
            title: '当前处理人',
            align: 'center',
            dataIndex: 'currentHandleUser',
            // scopedSlots: {customRender: 'fileSlot'},
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'exceptionBillStatus',
            scopedSlots: {customRender: 'exceptionBillStatus'},
          },
          /* {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          } */
        ],
        url: {
          // list: '/mes-manufacture/auto/mesMfAbnormalCall/list',
          // list: '/mes-manufacture/mfProductExceptionBillInfo/list',
          delete: '/mes-manufacture/auto/mesMfAbnormalCall/delete',
          deleteBatch: '/mes-manufacture/auto/mesMfAbnormalCall/deleteBatch',
          exportXlsUrl: '/mes-manufacture/auto/mesMfAbnormalCall/exportXls',
          importExcelUrl: '/mes-manufacture/auto/mesMfAbnormalCall/importExcel',
          getColumns: '/mes-manufacture/online/cgform/api/getColumns/',
          buttonAction: '/mes-manufacture/online/cgform/api/doButton',
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${api.test}${this.url.importExcelUrl}`;
      },
     getWidth:function(){
       if(this.defColumns.length > 14){
         return {width : '500px'}
       }
     },
     tableScroll:function(){
         if(this.columns.length > 13){
             return { x: this.columns.length*150-450 }
         }
     }
    },    
    created() {
      this.initButtonList();
      this.initColumns();
      this.setdefColumns();
      this.sysDictItem('mes_exception_status');
      this.sysDictItem('mes_exception_types');
    },

methods: {
    sysDictItem(params){
      productUnusual.sysDictItem(params).then( (res) =>{
        if ( res.code === 0 ){
          const curData = res.data;
          curData.forEach( el =>{
            if (params === 'mes_exception_status'){
              this.exceptionBillStatusMap[el.value] = el.text;
              // 保存到vuex
              this.$store.commit('setYcztMap', this.exceptionBillStatusMap);
            }else if (params === 'mes_exception_types'){
              this.exceptionTypeMap[el.value] = el.text;
              // 保存到vuex
              this.$store.commit('setYclxMap', this.exceptionTypeMap);
            }
          });
          this.dataSource.splice();
          console.log(this.exceptionBillStatusMap);
        }
      })
    },
    exceptionEventNumClick(row){
      this.componentId = "scclycd";
      this.visibleModal = true;
    },
    exceptionBillStatusClick(row){
      this.curRow = row;
      console.log(row.exceptionBillStatus);
      // 异常分配 主管
      if(row.exceptionBillStatus == 0){
        this.componentId = "yccl";
        // 待异常处置
      }else if (row.exceptionBillStatus == 1){
        this.componentId = "dycccz"; 
        }else if (row.exceptionBillStatus == 2){
        // 异常方案确认
        this.componentId = "ycclfaqr"; 
      }else if (row.exceptionBillStatus == 3){
        // 异常分配(PQE判定)'
        this.componentId = "ycfpPQEpd"; 
      }else if (row.exceptionBillStatus == 4){
        // 异常审核（主管审核）
        this.componentId = "ycsh"; 
      }else if (row.exceptionBillStatus == 5){
        // 异常处置（临时措施）
        this.componentId = "ycczlscs"; 
      }else if (row.exceptionBillStatus == 6){
        // 异常处置方案验证
        this.componentId = "ycczlscs";
      }else if (row.exceptionBillStatus == 7){
        // 原因分析及长期措施
        this.componentId = "yyjcqcs";
      }else if(row.exceptionBillStatus == 11){
        console.log('关闭');
      }
      this.visibleModal = true;
    },
    setdefColumns(){
        if(this.columns.length > 13){
        let arrLength = this.columns.length-1
        this.columns.forEach((item,index)=>{
          item["width"] = 130
        })
        this.columns[arrLength]['fixed'] = 'right'
        this.columns[0]['fixed'] = 'left'
        this.columns[0]['width'] = 60
        this.columns[1]['fixed'] = 'left'
        }
    },
    initColumns(){
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name+":colsettings";
      let colSettings= Vue.ls.get(key);
      if(colSettings==null||colSettings==undefined){
        let allSettingColumns = [];
        this.defColumns.forEach(function (item,i,array ) {
          allSettingColumns.push(item.dataIndex);
        })
        this.settingColumns = allSettingColumns;
        this.columns = this.defColumns;
      }else{
        this.settingColumns = colSettings;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true;
          }
          if (colSettings.includes(item.dataIndex)) {
            return true;
          }
          return false;
        })
        this.columns =  cols;
      }
    },
    //列设置更改事件
    onColSettingsChange (checkedValues) {
      var key = this.$route.name+":colsettings";
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues;
      const cols = this.defColumns.filter(item => {
        if(item.key =='rowIndex'|| item.dataIndex=='action'){
          return true
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      this.columns =  cols;
    },

      //高级查询方法
      handleSuperQuery(arg) {
          if(!arg){
              this.superQueryParams=''
              this.superQueryFlag = false
          }else{
              this.superQueryFlag = true
              this.superQueryParams=JSON.stringify(arg)
          }
          this.loadData()
      },
      // 获取查询条件
      getQueryParams() {
          let sqp = {}
          if(this.superQueryParams){
              sqp['superQueryParams']=encodeURI(this.superQueryParams)
          }
          var param = Object.assign(sqp, this.queryParam, this.isorter);
          param.field = this.getQueryField();
          param.pageNo = this.ipagination.current;
          param.limit = this.ipagination.pageSize;
          return filterObj(param);
      },
    initDictConfig(){
    },

    // 弹出窗组件
    showDemoModal() {
      this.$refs.modalCompon.modalShow();
    },
    // 点击btn获取数据
    btnGetData(tableName,title){
      getAction(`${this.url.getColumns}`,{
        tableName:tableName
      }).then(
        res=>{
          if(res.code == 0){
            this.queryInfo = res.data.columns
            this.title = title
            this.dictOptions = res.data.dictOptions
            this.showDemoModal()
          }else{
              this.$message.warning(res.msg);
          }
        }
      )
    },

    //筛选分组
    getGroupTag(arrList) {
      let arr = [];
      var map = {},
          dest = [];
      arrList.forEach((item, index) => {
        if (item.groupTag) {
          arr.push(item);
        }
      });
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i];
        if (!map[ai.groupTag]) {
          dest.push({
            groupTag: ai.groupTag,
            name: ai.groupName,
            data: [ai]
          });
          map[ai.groupTag] = ai;
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j];
            if (dj.groupTag == ai.groupTag) {
              dj.data.push(ai);
              break;
            }
          }
        }
      }
      this.groupTag = dest
      console.log(dest);
    },
    showLinkButton(item,record){
        let btn = new ButtonExpHandler(item.exp,record);
        return btn.show;
    },
      initButtonList(){
        getAction(`${this.url.getColumns}8ac49ec7733bce48017355ac0b13014e`).then((res)=>{
          console.log("--获取自定义按钮->>",res);
          if(res.success){
            this.code = res.data.code;
            this.initCgButtonList(res.data.cgButtonList);
            this.initCgEnhanceJs(res.data.enhanceJs);
            this.getGroupTag(res.data.cgButtonList);
          }else{
            this.$message.warning(res.msg)
          }
        })
      },
      initCgEnhanceJs(enhanceJs){
        //console.log("--onlineList-js增强",enhanceJs)
        if(enhanceJs){
          let Obj = eval ("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction,postAction,deleteAction);
          this.cgButtonJsHandler('created')
        }else{
          this.EnhanceJS = ''
        }
      },
      initCgButtonList(btnList){
        let linkArr = []
        let buttonArr = []
        if(btnList && btnList.length>0){
          for(let i=0;i<btnList.length;i++){
            let temp = btnList[i]
            if(temp.buttonStyle=='button'){
              buttonArr.push(temp)
            }else if(temp.buttonStyle=='link'){
              linkArr.push(temp)
            }
          }
        }
        this.cgButtonLinkList = [...linkArr]
        this.cgButtonList=[...buttonArr]
        console.log("链接增强", this.cgButtonLinkList);
      },
      cgButtonJsHandler(buttonCode){
        if(this.EnhanceJS[buttonCode]){
          this.EnhanceJS[buttonCode](this)
        }
      },
      cgButtonActionHandler(buttonCode){
        //处理自定义button的 需要配置该button自定义sql
        if(!this.selectedRowKeys || this.selectedRowKeys.length==0){
          this.$message.warning("请先选中一条记录")
          return false
        }
        if(this.selectedRowKeys.length>1){
          this.$message.warning("请只选中一条记录")
          return false
        }
        let params = {
          formId:this.code,
          buttonCode:buttonCode,
          dataId:this.selectedRowKeys[0]
        }
        console.log("自定义按钮请求后台参数：",params)
        postAction(this.url.buttonAction,params).then(res=>{
          if(res.success){
            this.loadData()
            this.$message.success("处理完成!")
          }else{
            this.$message.warning("处理失败!")
          }
        })

      },
      cgButtonLinkHandler(record,buttonCode,optType){
        if(optType=="js"){
          if(this.EnhanceJS[buttonCode]){
            this.EnhanceJS[buttonCode](this,record)
          }
        }else if(optType=="action"){
          let params = {
            formId:this.code,
            buttonCode:buttonCode,
            dataId:record.id
          }
          console.log("自定义按钮link请求后台参数：",params)
          postAction(this.url.buttonAction,params).then(res=>{
            if(res.success){
              this.loadData()
              this.$message.success("处理完成!")
            }else{
              this.$message.warning("处理失败!")
            }
          })
        }
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
<style  lang="less">
  .hTitle{
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 16px;
  }
</style>
